import { ref } from 'vue';

import { getDeptTree as api } from '#/api';

export const useDepartmentOptions = () => {
  // 部门树
  const deptTree = ref<any[]>([]);
  // 顶级为全部的部门树
  const withAllDeptTree = ref<any[]>([]);
  // 加载部门树
  const loadDeptTree = async () => {
    deptTree.value = await api();
  };
  // 加载顶级为全部的部门树
  const loadAllDeptTree = async () => {
    withAllDeptTree.value = [
      {
        deptName: '全部',
        id: '0',
        children: await api(),
      },
    ];
    return Promise.resolve(withAllDeptTree.value);
  };

  return {
    loadDeptTree,
    deptTree,
    loadAllDeptTree,
    withAllDeptTree,
  };
};
